<template>
  <j-modal
    :title="title"
    :width="600"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :rules="validatorRules" :model="form" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-form-model-item label="关键词" prop="content">
          <a-input class="input" v-model="form.content" />
        </a-form-model-item>
        <a-form-model-item label="关键词级别" prop="level">
          <j-dict-select-tag v-model="form.level" placeholder="请选择" dictCode="keywordLevel" />
        </a-form-model-item>
        <a-form-model-item label="关键词类别" prop="category">
          <j-dict-select-tag v-model="form.category" placeholder="请选择" dictCode="keywordType" />
        </a-form-model-item>
        <a-form-model-item label="关键词描述">
          <a-input class="input" v-model="form.description" />
        </a-form-model-item>
      </a-form-model>
    </a-spin>
    <template slot="footer">
      <a-button key="back" @click="handleCancel">取消</a-button>
      <a-button key="submit" type="primary" @click="handleOk">确定</a-button>
    </template>
  </j-modal>
</template>

<script>
import { save } from '@/api/wxSmuggle/keywordOptions.js'
export default {
  name: 'editModal',
  props: {
    title: {
      type: String,
      default: ''
    },
    // keyPersonnel走私重点人，samplesPersonnel负样本人员库
    type: {
      type: String,
      default: 'keyPersonnel'
    }
  },
  data() {
    return {
      visible: false,
      disableSubmit: false,
      form: {},
      labelCol: { span: 6 },
      wrapperCol: { span: 16 },
      confirmLoading: false,
      selectedKeys: null,
      validatorRules: {
        content: [{ required: true, message: '请输入关键词', trigger: 'change' }],
        level: [{ required: true, message: '请选择关键词级别', trigger: 'change' }],
        category: [{ required: true, message: '请选择关键词类型', trigger: 'change' }]
      }
    }
  },
  computed: {},
  methods: {
    add() {
      this.visible = true
      this.$nextTick(() => {
        this.form = {
          content: '',
          level: '',
          category: '',
          description: ''
        }
      })
    },
    edit(record) {
      this.visible = true
      this.form = Object.assign({}, record)
      this.$nextTick(() => {})
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      console.log(this.title)
      const method = save
      console.log(this.form)
      this.form.level = Number(this.form.level)
      this.form.category = Number(this.form.category)
      this.$refs.form.validate(valid => {
        if (valid) {
          save(this.form)
            .then(res => {
              if (res.success) {
                this.$message.success('提交成功！')
                this.$emit('ok')
                this.handleCancel()
              } else {
                this.$message.warn(res.message)
              }
            })
            .catch(e => {
              this.$message.warn('请求失败！')
            })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    handleCancel() {
      this.close()
    }
  }
}
</script>
<style lang="less" scoped></style>
